package cn.dckeji.dcssm.controller;

import cn.dckeji.dcssm.entity.*;
import cn.dckeji.dcssm.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author kenny
 * @Title: PageController
 * @ProjectName dcssm
 * @Description: TODO
 * @date 2019/1/2 9:31 AM
 */
@Controller
@RequestMapping("/page")
public class PageController {

    @Autowired
    private RoleService roleService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private RoleMenuService roleMenuService;
    @Autowired
    private MenuService menuService;
    @Autowired
    private DemoService demoService;

    /**
     * 跳转到登录页
     * @return
     */
    @GetMapping("/toLogin")
    public String toLogin() {
        return "login/login";
    }

    /**
     * 跳转到首页
     * @return
     */
    @GetMapping("/index")
    public String index() {
        return "index";
    }

    /**
     * 显示首页主体
     * @return
     */
    @GetMapping("/showMain")
    public String showMain() {
        return "main";
    }

    /**
     * 跳转修改管理员密码
     * @return
     */
    @GetMapping("/toChangePassWord")
    public String toChangePassWord() {
        return "changePassWord";
    }

    /**
     * 后台退出登录
     */
    @GetMapping(value = "/cancellation")
    public String cancellation(HttpSession session) {
        session.removeAttribute("remark");
        session.removeAttribute("adminId");
        return "login/login";
    }

    /**
     * 跳转到演示列表页面
     */
    @GetMapping("/toDemoList")
    public String toDemoList() {
        return "demo/list";
    }

    /**
     * 跳转到管理员列表
     * @return
     */
    @GetMapping("/toAdminList")
    public String toAdminList() {
        return "admin/list";
    }


    @GetMapping("/toUsersList")
    public String toUsersList() {
        return "users/list";
    }



    @GetMapping("/toHisList")
    public String toHisList() {
        return "his/list";
    }

    @Autowired
    private CountdownService countdownService;

    @GetMapping("/toSetting")
    public String toSetting(HttpServletRequest request) {
        Countdown aaaaaaaaaa = countdownService.getById("aaaaaaaaaa");
        request.setAttribute("record", aaaaaaaaaa);
        return "his/list2";
    }


    @GetMapping("/toParkList")
    public String toParkList() {
        return "park/list";
    }
    /**
     * 跳转到管理员编辑页
     * @param adminId
     * @param request
     * @return
     */
    @GetMapping("/toEditAdmin")
    public String toEditAdmin(String adminId, HttpServletRequest request) {
        //查询所有的角色
        List<Role> roleList = roleService.list();

        if (StringUtils.isNotBlank(adminId)) {
            Admin admin = adminService.getById(adminId);
            request.setAttribute("admin", admin);
        }
        request.setAttribute("roleList", roleList);
        return "admin/edit";
    }



  @Autowired
  private  UsersService usersService;
    /**
     * 跳转到管理员编辑页
     * @param
     * @param request
     * @return
     */
    @GetMapping("/toEditUsers")
    public String toEditUsers(String userId, HttpServletRequest request) {
        if (StringUtils.isNotBlank(userId)) {
            Users byId = usersService.getById(userId);
            request.setAttribute("admin", byId);
        }
        return "users/edit";
    }

@Autowired
private  ParkService  parkService;
    /**
     * 跳转到管理员编辑页
     * @param
     * @param request
     * @return
     */
    @GetMapping("/toEditPark")
    public String toEditPark(String parkId, HttpServletRequest request) {
        if (StringUtils.isNotBlank(parkId)) {
            Park byId = parkService.getById(parkId);
            request.setAttribute("admin", byId);
        }
        return "park/edit";
    }


    /**
     * 跳转到角色列表
     */
    @GetMapping("/toRoleList")
    public String toRoleList() {
        return "role/list";
    }

    /**
     * 跳转到编辑角色页面
     * @param roleId
     * @param request
     */
    @GetMapping("/toEditRole")
    public String toEditRole(String roleId, HttpServletRequest request) {
        if (StringUtils.isNotBlank(roleId)) {
            Role role = roleService.getById(roleId);
            request.setAttribute("role", role);
        }
        return "role/edit";
    }

    /**
     * 跳转到demo编辑页
     * @param demoId
     * @param request
     * @return
     */
    @GetMapping("/toEditDemo")
    public String toEditDemo(String demoId, HttpServletRequest request) {

        if (StringUtils.isNotBlank(demoId)) {
            Demo demo = demoService.getById(demoId);
            request.setAttribute("demo", demo);
        }
        return "demo/edit";
    }

    /**
     * 跳转到菜单管理页面
     * @return
     */
    @GetMapping("/toSettingMenu")
    public String toSettingMenu() {
        return "menu/menu";
    }

    /**
     * 跳转到添加一级菜单
     */
    @GetMapping("/toEditMenu")
    public String toEditMenu() {
        return "menu/add";
    }

    /**
     * 跳转到日志列表
     * @return
     */
    @GetMapping("/toErrorLogList")
    public String toErrorLogList() {
        return "log/list";
    }
}
